<template>
  <view class="detail-container">
    <!-- 顶部图片区域 -->
    <view class="detail-header">
      <image :src="currentItem.image" mode="aspectFill" class="detail-image"></image>
      <view class="image-overlay"></view>
      <view class="back-btn" @click="goBack">
        <text class="icon-back">←</text>
      </view>
    </view>


    <!-- 内容区域 -->
    <view class="detail-content">
      <!-- 标题和评分 -->
      <view class="title-section">
        <view class="detail-title">{{ currentItem.title || '美食详情' }}</view>
        <view class="rating-box" v-if="currentItem.rating">
          <text class="rating-star">★</text>
          <text class="rating-value">{{ currentItem.rating }}</text>
        </view>
      </view>
      
      <!-- 描述 -->
      <view class="description-card">
        <text class="description-text">{{ currentItem.description }}</text>
      </view>
      
      <!-- 基本信息卡片 -->
      <view class="info-card">
        <view class="card-title">基本信息</view>
        <view class="info-grid">
          <view class="info-item" v-if="currentItem.price">
            <view class="info-icon">💰</view>
            <view class="info-content">
              <view class="info-label">价格</view>
              <view class="info-value price">{{ currentItem.price }}</view>
            </view>
          </view>
          
          <view class="info-item" v-if="currentItem.cookingTime">
            <view class="info-icon">⏱️</view>
            <view class="info-content">
              <view class="info-label">烹饪时间</view>
              <view class="info-value">{{ currentItem.cookingTime }}</view>
            </view>
          </view>
          
          <view class="info-item" v-if="currentItem.difficulty">
            <view class="info-icon">⚡</view>
            <view class="info-content">
              <view class="info-label">难度</view>
              <view class="info-value">{{ currentItem.difficulty }}</view>
            </view>
          </view>
          
          <view class="info-item" v-if="currentItem.origin">
            <view class="info-icon">📍</view>
            <view class="info-content">
              <view class="info-label">起源</view>
              <view class="info-value">{{ currentItem.origin }}</view>
            </view>
          </view>
        </view>
      </view>
      
      <!-- 食材 -->
      <view class="info-card" v-if="currentItem.ingredients">
        <view class="card-title">主要食材</view>
        <view class="ingredients-list">
          <text v-for="(ingredient, index) in currentItem.ingredients" 
                :key="index" 
                class="ingredient-tag">
            {{ ingredient }}
          </text>
        </view>
      </view>
      
      <!-- 制作步骤 -->
      <view class="info-card" v-if="currentItem.steps">
        <view class="card-title">制作步骤</view>
        <view class="steps-list">
          <view v-for="(step, index) in currentItem.steps" 
                :key="index" 
                class="step-item">
            <view class="step-number">{{ index + 1 }}</view>
            <view class="step-content">{{ step }}</view>
          </view>
        </view>
      </view>
      
      <!-- 小贴士 -->
      <view class="tips-card" v-if="currentItem.tips">
        <view class="tips-icon">💡</view>
        <view class="tips-content">
          <view class="tips-title">小贴士</view>
          <view class="tips-text">{{ currentItem.tips }}</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { BASE_URL } from "../../utils/api";

const currentItem = ref({})

const goBack = () => {
  uni.navigateBack()
}

onLoad((options) => {
  console.log('接收到的参数:', options)
  
  // 龙川美食数据映射
  const foodData = {
    // 龙川粑粑
    'longchuan-baba.jpg': {
      title: '龙川粑粑',
      description: '龙川粑粑 - 精选本地糯米，配以花生、芝麻等馅料，蒸制后软糯香甜，是客家传统节日的重要食品。',
      image: `${BASE_URL}/food/longchuan-baba.jpg`,
      price: '¥25',
      rating: '4.8',
      ingredients: ['糯米', '花生', '芝麻', '白糖', '粽叶'],
      cookingTime: '45分钟',
      difficulty: '中等',
      steps: [
        '糯米浸泡4小时以上',
        '花生芝麻炒香碾碎',
        '糯米与馅料混合包裹',
        '用粽叶包裹蒸制40分钟'
      ],
      tips: '蒸制时火候要均匀，时间要充足',
      origin: '客家传统节日食品'
    },
    // 客家擂茶
    'hakka-leicha.jpg': {
      title: '客家擂茶',
      description: '客家擂茶 - 将绿茶、芝麻、花生、薄荷等原料在擂钵中研磨成粉，冲泡饮用，清香解渴，养生保健。',
      image: `${BASE_URL}/food/hakka-leicha.jpg`,
      price: '¥15',
      rating: '4.7',
      ingredients: ['绿茶', '芝麻', '花生', '薄荷', '食盐'],
      cookingTime: '15分钟',
      difficulty: '简单',
      steps: [
        '将茶叶、芝麻、花生放入擂钵',
        '用擂棍慢慢研磨成粉末',
        '加入薄荷叶继续研磨',
        '冲入开水搅拌即可饮用'
      ],
      tips: '研磨时要耐心，让原料充分融合',
      origin: '客家传统饮品'
    },
    // 龙川腐竹
    'yuba.jpg': {
      title: '龙川腐竹',
      description: '龙川腐竹 - 选用优质黄豆，传统工艺制作，豆香浓郁，营养丰富，可炖汤、炒菜，做法多样。',
      image: `${BASE_URL}/food/yuba.jpg`,
      price: '¥20',
      rating: '4.6',
      ingredients: ['黄豆', '清水'],
      cookingTime: '需要泡发',
      difficulty: '简单',
      steps: [
        '黄豆精选浸泡',
        '磨浆过滤煮沸',
        '表面结皮后挑起',
        '晾晒干燥即成腐竹'
      ],
      tips: '泡发时用温水，时间约30分钟',
      origin: '传统豆制品'
    },
    // 客家腊味
    'cured-meat.jpg': {
      title: '客家腊味',
      description: '客家腊味 - 包括腊肠、腊肉、腊鸭等，经盐腌、日晒、风干而成，腊香扑鼻，风味独特。',
      image: `${BASE_URL}/food/cured-meat.jpg`,
      price: '¥48',
      rating: '4.9',
      ingredients: ['猪肉', '肠衣', '食盐', '白糖', '白酒', '酱油'],
      cookingTime: '需要风干',
      difficulty: '较难',
      steps: [
        '猪肉切条调味腌制',
        '灌入肠衣制成腊肠',
        '在通风处晾晒风干',
        '约15-20天即可食用'
      ],
      tips: '晾晒时要避免雨水，保持通风',
      origin: '客家传统腌制食品'
    },
    // 芋头饺
    'taro-dumpling.jpg': {
      title: '芋头饺',
      description: '芋头饺 - 芋头蒸熟捣泥作皮，包裹猪肉、香菇等馅料，蒸制后芋香四溢，口感绵密。',
      image: `${BASE_URL}/food/taro-dumpling.jpg`,
      price: '¥32',
      rating: '4.8',
      ingredients: ['芋头', '木薯粉', '猪肉', '香菇', '虾米', '调味料'],
      cookingTime: '35分钟',
      difficulty: '中等',
      steps: [
        '芋头蒸熟捣成泥状',
        '加入木薯粉揉成面团',
        '准备猪肉香菇馅料',
        '包成饺子蒸制15分钟'
      ],
      tips: '芋头要趁热捣泥，口感更佳',
      origin: '客家特色小吃'
    },
    // 客家娘酒
    'rice-wine.jpg': {
      title: '客家娘酒',
      description: '客家娘酒 - 用糯米酿造，酒色澄黄，味道甘甜，具有驱寒暖身、补气养血的功效。',
      image: `${BASE_URL}/food/rice-wine.jpg`,
      price: '¥38',
      rating: '4.7',
      ingredients: ['糯米', '酒曲', '清水'],
      cookingTime: '需要发酵',
      difficulty: '较难',
      steps: [
        '糯米浸泡蒸熟',
        '摊凉后拌入酒曲',
        '装入酒缸发酵',
        '约30天后过滤装瓶'
      ],
      tips: '发酵温度要控制在25-30度',
      origin: '客家传统酒饮'
    },
    // 酿豆腐
    'stuffed-tofu.jpg': {
      title: '酿豆腐',
      description: '酿豆腐 - 新鲜豆腐挖空填入肉馅，先煎后焖，豆腐嫩滑，肉馅鲜美，是客家代表性菜肴。',
      image: `${BASE_URL}/food/stuffed-tofu.jpg`,
      price: '¥28',
      rating: '4.9',
      ingredients: ['豆腐', '猪肉', '香菇', '葱花', '调味料'],
      cookingTime: '25分钟',
      difficulty: '中等',
      steps: [
        '豆腐切块中间挖空',
        '猪肉香菇剁碎调味',
        '将肉馅酿入豆腐中',
        '煎至金黄后焖煮'
      ],
      tips: '煎的时候要轻翻，避免豆腐破碎',
      origin: '客家代表性菜肴'
    }
  }
  
  // 方法1：直接使用 fileName 参数
  const fileName = options.fileName
  console.log('文件名:', fileName)
  
  // 方法2：如果 fileName 不存在，尝试从 image 参数提取
  if (!fileName && options.image) {
    const imagePath = options.image
    const extractedFileName = imagePath.split('/').pop()
    console.log('从image参数提取的文件名:', extractedFileName)
    
    // 设置当前项目
    currentItem.value = foodData[extractedFileName] || foodData['longchuan-baba.png']
  } else {
    // 设置当前项目
    currentItem.value = foodData[fileName] || foodData['longchuan-baba.png']
  }
  
  console.log('最终显示的数据:', currentItem.value)
})
</script>

<style scoped>
.detail-container {
  background: #f8f9fa;
  min-height: 100vh;
}

/* 顶部图片区域 */
.detail-header {
  position: relative;
  height: 400rpx;
  overflow: hidden;
}

.detail-image {
  width: 100%;
  height: 100%;
}

.image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to bottom, transparent 60%, rgba(0,0,0,0.4));
}

.back-btn {
  position: absolute;
  top: 80rpx;
  left: 30rpx;
  width: 70rpx;
  height: 70rpx;
  background: rgba(255,255,255,0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.1);
}

.icon-back {
  font-size: 36rpx;
  color: #333;
}

/* 内容区域 */
.detail-content {
  position: relative;
  margin-top: -60rpx;
  background: #fff;
  border-radius: 30rpx 30rpx 0 0;
  padding: 40rpx 30rpx;
}

/* 标题区域 */
.title-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 30rpx;
}

.detail-title {
  font-size: 42rpx;
  font-weight: bold;
  color: #333;
  flex: 1;
}

.rating-box {
  background: #ff6b6b;
  padding: 8rpx 16rpx;
  border-radius: 20rpx;
  display: flex;
  align-items: center;
  gap: 8rpx;
}

.rating-star {
  color: #fff;
  font-size: 24rpx;
}

.rating-value {
  color: #fff;
  font-size: 26rpx;
  font-weight: bold;
}

/* 描述卡片 */
.description-card {
  background: #f8f9fa;
  padding: 30rpx;
  border-radius: 20rpx;
  margin-bottom: 40rpx;
  border-left: 6rpx solid #ffd166;
}

.description-text {
  font-size: 30rpx;
  line-height: 1.6;
  color: #555;
}

/* 信息卡片通用样式 */
.info-card {
  background: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.06);
  border: 1rpx solid #f0f0f0;
}

.card-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 25rpx;
  padding-bottom: 15rpx;
  border-bottom: 2rpx solid #f0f0f0;
}

/* 基本信息网格 */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 25rpx;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 20rpx;
}

.info-icon {
  font-size: 36rpx;
  width: 60rpx;
  height: 60rpx;
  background: #f8f9fa;
  border-radius: 12rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.info-content {
  flex: 1;
}

.info-label {
  font-size: 24rpx;
  color: #999;
  margin-bottom: 5rpx;
}

.info-value {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
}

.price {
  color: #ff6b6b;
  font-weight: bold;
}

/* 食材标签 */
.ingredients-list {
  display: flex;
  flex-wrap: wrap;
  gap: 20rpx;
}

.ingredient-tag {
  background: #e9f7ef;
  color: #27ae60;
  padding: 12rpx 24rpx;
  border-radius: 25rpx;
  font-size: 26rpx;
  border: 1rpx solid #a3e4b9;
}

/* 制作步骤 */
.steps-list {
  display: flex;
  flex-direction: column;
  gap: 25rpx;
}

.step-item {
  display: flex;
  gap: 20rpx;
  align-items: flex-start;
}

.step-number {
  width: 50rpx;
  height: 50rpx;
  background: #4ecdc4;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24rpx;
  font-weight: bold;
  flex-shrink: 0;
  margin-top: 5rpx;
}

.step-content {
  flex: 1;
  font-size: 28rpx;
  line-height: 1.5;
  color: #555;
  padding-top: 8rpx;
}

/* 小贴士卡片 */
.tips-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 20rpx;
  padding: 30rpx;
  display: flex;
  gap: 20rpx;
  align-items: flex-start;
}

.tips-icon {
  font-size: 36rpx;
  margin-top: 5rpx;
}

.tips-content {
  flex: 1;
}

.tips-title {
  font-size: 28rpx;
  color: #fff;
  font-weight: bold;
  margin-bottom: 10rpx;
}

.tips-text {
  font-size: 26rpx;
  color: rgba(255,255,255,0.9);
  line-height: 1.5;
}
</style>